package com.bym.mall.config;


import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.http.HttpSession;

/**
 * swagger配置类
 *
 * @author zhaoqiting
 * @date 2022/06/22
 */
@EnableSwagger2
@SpringBootConfiguration
public class SwaggerConfig {

    @Bean   //在启动时初始化，返回实例例 Docket（Swagger API 摘要）
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .ignoredParameterTypes(HttpSession.class)
                .select()
                // 自行修改为自己的包路径
                .apis(RequestHandlerSelectors.basePackage("com.bym.mall.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //标题
                .title("mall")
                //描述
                .description("mall API 1.0 操作文档")
                //服务条款网址
                .termsOfServiceUrl("http://www.bym.com/")
                //版本
                .version("1.0")
                //联系方式
                .contact(new Contact("八月墨", "http://www.bym.com/", "19883136690@163.com"))
                .build();
    }
}